using System;

using OR.Reuse.Persistence;

using OR.Lazarus.Config;

using Notation			= OR.Lazarus.Business.Entities.Notation;

namespace OR.Lazarus.Business
{
	/// <summary>
	/// Summary description for CompilerBase.
	/// </summary>
	public abstract class CompilerBase< SOURCE, COMPILED, VALIDATOR >
      where SOURCE : IProject, new()
      where COMPILED : IProject, new()
      where VALIDATOR : IProjectValidator<SOURCE>, new()
	{
      protected SOURCE mSourceProject;
      protected COMPILED mCompiledProject;
      protected VALIDATOR mSourceValidator;

		public CompilerBase()
		{
         mSourceProject = new SOURCE();
         mCompiledProject = new COMPILED();
         mSourceValidator = new VALIDATOR();
		}

      protected virtual void OnBeforeCompile( EventArgs e )
      {
         this.OnValidate();

         this.OnApplyDefaults();
      }

      protected virtual void OnAfterCompile( EventArgs e )
      {

      }

		public void Compile()
		{
         this.OnBeforeCompile( new EventArgs() );

         this.OnCompile();

         this.OnAfterCompile( new EventArgs() );
		}

		#region Properties
		public SOURCE SourceProject
		{
			get
			{
				return ( mSourceProject );
			}
			set
			{
				mSourceProject = value;
			}
		}

		public COMPILED CompiledProject
		{
			get
			{
				return ( mCompiledProject );
			}
			set
			{
				mCompiledProject = value;
			}
		}
		#endregion

		#region Validation
		protected virtual void OnValidate()
		{
         mSourceValidator.Project = mSourceProject;

         mSourceValidator.DoValidate();
		}
		#endregion

      #region Standards/Defaults Application
      
      protected virtual void OnApplyDefaults()
      {
      }

      #endregion

		#region Compiler
		protected virtual void OnCompile()
		{
			this.OnCompileProject( mSourceProject );
      }

      protected abstract void OnCompileProject( SOURCE pSource );

		#endregion
	}
}
